// 修正IE7以下的PNG背景透明
/*var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);

function fixPNG(myImage){
    if((version >= 5.5) && (version < 7) && (document.body.filters)){
       var img = myImage;
	   var imgID = (myImage.id) ? "id='" + myImage.id + "' " : "";
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : "";
	   var imgTitle = (myImage.title) ?  "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' ";
	   var imgStyle = "display:inline-block;" + myImage.style.cssText;
       if(img.align == "left") imgStyle = "float:left;" + imgStyle;
       if(img.align == "right") imgStyle = "float:right;" + imgStyle;
	   if(img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width
                  + "px; height:" + myImage.height
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>";
	   myImage.outerHTML = strNewHTML; 
    }
}*/

// 获取整个文档的高度，需要引入 jQuery
function dHeihgt(){
	return $(window.document).height();
}

// 函数：获取尺寸，http://www.ibm.com/developerworks/cn/web/wa-adaptapps/index.html
function getDimensions(){
	var scrollLeft,scrollTop;

	if(window.pageYOffset){  
		scrollTop = window.pageYOffset 
	} else if(document.documentElement && document.documentElement.scrollTop){ 
		scrollTop = document.documentElement.scrollTop; 
	} else if(document.body){ 
		scrollTop = document.body.scrollTop; 
	} 

	if(window.pageXOffset){ 
		scrollLeft = window.pageXOffset 
	} else if(document.documentElement && document.documentElement.scrollLeft){ 
		scrollLeft = document.documentElement.scrollLeft; 
	} else if(document.body){ 
		scrollLeft = document.body.scrollLeft; 
	}

	var windowWidth,windowHeight; // frame width & height

	if(window.innerWidth){ 
		windowWidth = window.innerWidth; 
	} else if(document.documentElement && document.documentElement.clientWidth){ 
		windowWidth = document.documentElement.clientWidth; 
	} else if(document.body){ 
		windowWidth = document.body.offsetWidth; 
	} 

	if(window.innerHeight){ 
		windowHeight = window.innerHeight; 
	} else if(document.documentElement && document.documentElement.clientHeight){ 
		windowHeight = document.documentElement.clientHeight; 
	} else if(document.body){ 
		windowHeight = document.body.clientHeight; 
	}
	
	return {
		l: scrollLeft,
		t: scrollTop,
		w: windowWidth,
		h: windowHeight
	};
}

/**  
 * 格式化数字显示方式   
 * 用法  
 * formatNumber(12345.999,'#,##0.00');  
 * formatNumber(12345.999,'#,##0.##');  
 * formatNumber(123,'000000');  
 * @param num  
 * @param pattern
 * url	http://www.javaeye.com/topic/161249
 */  
function formatNumber(num,pattern){   
  var strarr = num?num.toString().split('.'):['0'];   
  var fmtarr = pattern?pattern.split('.'):[''];   
  var retstr='';   
  
  // 整数部分   
  var str = strarr[0];   
  var fmt = fmtarr[0];   
  var i = str.length-1;     
  var comma = false;   
  for(var f=fmt.length-1;f>=0;f--){   
    switch(fmt.substr(f,1)){   
      case '#':   
        if(i>=0) retstr = str.substr(i--,1) + retstr;   
        break;   
      case '0':   
        if(i>=0) retstr = str.substr(i--,1) + retstr;   
        else retstr = '0' + retstr;   
        break;   
      case ',':   
        comma = true;   
        retstr=','+retstr;   
        break;   
    }   
  }   
  if(i>=0){   
    if(comma){   
      var l = str.length;   
      for(;i>=0;i--){   
        retstr = str.substr(i,1) + retstr;   
        if(i>0 && ((l-i)%3)==0) retstr = ',' + retstr;    
      }   
    }   
    else retstr = str.substr(0,i+1) + retstr;   
  }   
  
  retstr = retstr+'.';   
  // 处理小数部分   
  str=strarr.length>1?strarr[1]:'';   
  fmt=fmtarr.length>1?fmtarr[1]:'';   
  i=0;   
  for(var f=0;f<fmt.length;f++){   
    switch(fmt.substr(f,1)){   
      case '#':   
        if(i<str.length) retstr+=str.substr(i++,1);   
        break;   
      case '0':   
        if(i<str.length) retstr+= str.substr(i++,1);   
        else retstr+='0';   
        break;   
    }   
  }   
  return retstr.replace(/^,+/,'').replace(/\.$/,'');
}

/**
 * 功能：约束图片大小
 * @param {Object} ImgD 图片句柄
 * @param {int} width 目标宽度
 * @param {int} height 目标高度
 */
function drawImage(ImgD, width, height){
    var flag = false;
    var image = new Image();
     
    image.src = ImgD.src;
    if(image.width > 0 && image.height > 0){
        flag = true;
        if(image.height > height){
            ImgD.height = height;
            ImgD.width = (image.width * height) / image.height;
            if(ImgD.width > width){
				tmp = ImgD.width;
				ImgD.width = width;
				ImgD.height = (width * ImgD.height) / tmp;
            }
        }
        else {
            if(image.width > width){
                ImgD.width = width;
                ImgD.height = (image.height * width) / image.width;
                if(ImgD.height > height){
                    tmp = ImgD.height;
					ImgD.height = height;
					ImgD.width = (height * ImgD.width) / tmp;
                }
            }
            else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
        ImgD.alt = image.width + "×" + image.height;
    }
}


function cal_time_duration(seconds){
	times = [];
	if(seconds >= 86400){
		times.push(Math.floor(seconds / 86400)+'天');
		seconds = seconds % 86400;
	}
	if(seconds >= 3600){
		times.push(Math.floor(seconds / 3600)+'小时');
		seconds = seconds % 3600;
	}
	if(seconds >= 60){
		times.push(Math.floor(seconds / 60)+'分钟');
		seconds = seconds % 60;
	}
	if(seconds > 0){
		times.push(seconds+'秒');
	}
	return times.join('');
}


/*******************************************************************************
 * COOKIE
 *******************************************************************************/

function get_cookie(cookie_name){
	cookie_name = _s['cookie_pre']+cookie_name;
	// cookies are separated by semicolons
	var arr_cookie = document.cookie.split("; ");
	for(var i = 0; i < arr_cookie.length; i++){
		// a name/value pair (a crumb) is separated by an equal sign
		var arr_crumb = arr_cookie[i].split("=");
		if (cookie_name == arr_crumb[0]){
			return decodeURIComponent(arr_crumb[1]);
		}
	}

	// a cookie with the requested name does not exist
	return null;
}

function set_cookie(cookie_name, cookie_val, expires, path){
	cookie_name = _s['cookie_pre']+cookie_name;
	var sCookie = cookie_name + "=" + encodeURIComponent(cookie_val);
	var date = new Date();
	expires = parseInt(expires);
	expires = expires > 0 ? expires : 3600;
	expires *= 1000;
	date.setTime(date.getTime() + expires);
	expires = date.toGMTString();
	sCookie += "; expires=" + expires;
	path = path || '/';
	sCookie += ";path="+path;

	document.cookie = sCookie;
}

function remove_cookie(cookie_name){
	document.cookie = cookie_name + "=; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}


/*******************************************************************************
 * DOM
 *******************************************************************************/

function gi(id){
	if(document.getElementById){
		return eval('document.getElementById("'+id+'")');
	}else if(document.layers){
		return eval("document.layers['"+id +"']");
	}else{
		return eval('document.all.'+id);
	}
}

/*******************************************************************************
 * 打开（创建）弹出层
 *******************************************************************************/

// 触发iframe事件
function toggle_iframe_func(action){
	var iframe_obj = document.getElementById('float_iframe');
	if (!iframe_obj) {
		return false;
	}
	action = action || '_transmit';	// 这种情况，一般是打开弹出层筛选数据
	try{
		if(typeof(window.float_iframe[action]) == 'function'){
			iframe_obj.contentWindow[action]();
			// window.float_iframe[action]();
		}
	}catch(e){
		showmsg_warning('方法【'+action+'】不存在！！！');
		//close_div();
	}
}

// 关闭层
function close_div(){
	$('#float_div').dialog('close');
}

function open_div(options){
	var div_id = 'float_div';
	var div_obj = document.getElementById('float_div');
	if(!div_obj){
		try{
			div_obj = document.createElement('<div id="'+div_id+'" class="hide"></div>');
		}catch(e){
			div_obj = document.createElement('div');
			div_obj.id 			= div_id;
			div_obj.className	= 'hide';
		}
	}
	var action	= options.action || false;
	try{
		if(action == false && $(div_obj).dialog('isOpen')){
			var defaults = {
				position: {
					using: function( pos ) {
						$(this).css({top: pos.top});
					}
				}
			};
		    var opts = $.extend(defaults, options);
			$(div_obj).dialog('option', opts);
			return div_obj;
		}
	}catch(e){}
	
	var defaults = {
		modal		: false
		,autoOpen	: false
		,title		: ''
		,width		: $(window).width() - 40
		,height		: 600
		// ,zIndex		: 5000
		// ,url			: ''
		// ,win			: ''
		,buttons		: {
			"确定"	: function() {toggle_iframe_func(action);}, 
			"关闭"	: function() {$(this).dialog('close');} 
		}
		,close		: function(){
			$(this).dialog("destroy");
		}
	}; 
    var opts = $.extend(defaults, options);
    
	// 初始化对话框
	/*try{
		$(div_obj).dialog('destroy');
	}catch(e){}*/
	$(div_obj).dialog(opts).dialog('open');
	return div_obj;
}

function open_frame(options){
    /*if(opts.win == 'list'){
    	try{
			show_ibody();	// 切换到列表窗口
		}catch(e){
			// do nothing
		}
    }*/
    
	var div_obj = open_div(options);
	
	if(options.url != ''){
		iframe_id = 'float_iframe';
		var iframe_obj = document.getElementById('float_iframe');
	    if(!iframe_obj){
	        try{	// $.browser.msie
	            iframe_obj = document.createElement('<iframe name="'+iframe_id+'" id="'+iframe_id+'" frameborder="0" width="100%" height="100%"></iframe>');
	        }catch(e){
				iframe_obj				= document.createElement('iframe');
				iframe_obj.name			= iframe_id;
				iframe_obj.id			= iframe_id;
				iframe_obj.frameborder	= 0;
				iframe_obj.width		= '100%';
				iframe_obj.height		= '100%';
				iframe_obj.style.border	= 'none';
	        }
	        iframe_obj.loading = 1;
	        div_obj.appendChild(iframe_obj);
	    }
	    if(options.url.indexOf('?') == -1){
	    	options.url += '?';
	    }
	    options.url += '&_iframe=yes';
	    options.url.replace('?&', '?');
		iframe_obj.src = options.url;
	}
	
	return false;
}

/*******************************************************************************
 * 是否数组判断
 *******************************************************************************/

function isArray(object){	// jQuery里面有，此处可以去掉
	return object && typeof object==='object' &&    
        	typeof object.length==='number' &&  
        	typeof object.splice==='function' &&    
        	 //判断length属性是否是可枚举的 对于数组 将得到false  
        	!(object.propertyIsEnumerable('length'));
}

function inArray(needle, array){
	if(!isArray(array))return -1;
    if(typeof needle=='string' || typeof needle=='number'){  
        for(var i in array){  
            if(needle === array[i]){  
                return i;  
            }  
        }  
        return -1;  
    }  
}


/*******************************************************************************
 * 浏览器类型检测
 *******************************************************************************/

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera",
			versionSearch: "Version"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
// BrowserDetect.init();
// You\'re using ' + BrowserDetect.browser + ' ' + BrowserDetect.version + ' on ' + BrowserDetect.OS
// BrowserDetect.browser	Firefox、Explorer、Chrome
// BrowserDetect.version	19、8、25
// BrowserDetect.OS		Windows